package com.springbootbase.springbootproject.controller;


import com.springbootbase.springbootproject.pojo.ListResponse;
import com.springbootbase.springbootproject.pojo.Recommendationcontact;
import com.springbootbase.springbootproject.pojo.Result;
import com.springbootbase.springbootproject.service.RecommendationContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Objects;

//推荐联系
@RestController
@RequestMapping("/recommend")
public class recommendController {
    @Autowired
    private RecommendationContactService recommendationContactService;

    @PostMapping("/sendInvite")
    public Result sendInvite(Long student_id,Long teacher_id,String initiator,String initiator_info,String initiator_message){
        Recommendationcontact recommendationcontact = new Recommendationcontact();
        recommendationcontact.setStudentId(student_id);
        recommendationcontact.setTeacherId(teacher_id);
        recommendationcontact.setInitiator(initiator);
        if (Objects.equals(initiator, "student")) {
            recommendationcontact.setStudentContactInfo(initiator_info);
            recommendationcontact.setStudentMessage(initiator_message);
        }else {
            recommendationcontact.setTeacherContactInfo(initiator_info);
            recommendationcontact.setTeacherMessage(initiator_message);
        }
        recommendationcontact.setCreateAt(LocalDate.now());
        recommendationcontact.setContactStatus(0);
        recommendationContactService.sendInvite(recommendationcontact);
        return Result.success();
    }

    @GetMapping("/getContactList")
    public Result<ArrayList> getInviteList(Long id){
        ArrayList<Recommendationcontact> recommendationcontactArrayList = recommendationContactService.getInviteList(id);
        return Result.success(recommendationcontactArrayList);
    }

    @GetMapping("/getSendContact")
    public  Result<ArrayList> getSendContact(Long id){
        ArrayList<Recommendationcontact> recommendationcontactArrayList = recommendationContactService.getSendList(id);
        return Result.success(recommendationcontactArrayList);
    }

    @PostMapping("/acceptContact")
    public  Result acceptContact(Long contact_id, String accept_info,String accept_message,String initiator){
        recommendationContactService.acceptContact(contact_id,accept_info,accept_message,initiator);
        return Result.success();
    }

    @GetMapping("/acceptAllContact")
    public Result  acceptAllContact(Long id,int pageSize,int pageNum){
       ListResponse recommendationcontactArrayList = recommendationContactService.acceptAll(id,pageSize,pageNum);
       return Result.success(recommendationcontactArrayList);
    }

    @GetMapping("/refuseContact")
    public Result refuseContact(Long studentId,Long teacherId){
        recommendationContactService.refuseContact(studentId,teacherId);
        return Result.success();
    }

    @GetMapping("/withdraw")
    public Result withdrawContact(Long contactId){
        recommendationContactService.withdrawContact(contactId);
        return Result.success();
    }

    @GetMapping("/allContact")
    public Result<ArrayList> allContact(Long id){
        ArrayList<Recommendationcontact> recommendationcontactArrayList = recommendationContactService.allContact(id);
        return  Result.success(recommendationcontactArrayList);
    }
}
